﻿using System.Collections.Generic;
using SW.Lite.IDAL;
using SW.Lite.Infrastructure.Common;
using SW.Lite.Infrastructure.Service;
using SW.Lite.Model;

namespace SW.Lite.BLL
{
    public class Column
    {
        private static readonly IColumn Dal = ServiceLocator.Instance.GetInstance<IColumn>("Column");

        /// <summary>
        ///     数据是否存在
        /// </summary>
        /// <param name="id">ID</param>
        public static bool Exists(int id)
        {
            return Dal.Exists(id);
        }

        /// <summary>
        ///     获取单个项
        /// </summary>
        /// <param name="id">ID</param>
        public static ColumnModel Single(int id)
        {
            return Dal.Single(id);
        }

        /// <summary>
        ///     获取所有项目
        /// </summary>
        public static PageList<ColumnModel> All()
        {
            return Dal.All();
        }

        /// <summary>
        ///     获取所有项目
        /// </summary>
        /// <param name="pageIndex">页索引</param>
        /// <param name="pageSize">页大小</param>
        public static PageList<ColumnModel> All(int pageIndex, int pageSize)
        {
            return Dal.All(pageIndex, pageSize);
        }

        /// <summary>
        ///     插入数据
        /// </summary>
        /// <param name="model">单个项</param>
        public static ExecuteResult Insert(ColumnModel model)
        {
            return Dal.Insert(model);
        }

        /// <summary>
        ///     更新数据
        /// </summary>
        /// <param name="model">单个项</param>
        public static ExecuteResult Update(ColumnModel model)
        {
            return Dal.Update(model);
        }

        /// <summary>
        ///     删除数据
        /// </summary>
        /// <param name="id">ID</param>
        public static ExecuteResult Delete(int id)
        {
            return Dal.Delete(id);
        }

        /// <summary>
        ///     获取一级栏目
        /// </summary>
        public static PageList<ColumnModel> GetTops()
        {
            return Dal.GetTops();
        }

        /// <summary>
        ///     保存排序号
        /// </summary>
        /// <param name="columnSorts">栏目排序号</param>
        public static ExecuteResult SaveSorts(Dictionary<int, int> columnSorts)
        {
            return Dal.SaveSorts(columnSorts);
        }

        /// <summary>
        ///     获取子栏目
        /// </summary>
        /// <param name="columnId">父栏目ID</param>
        public static PageList<ColumnModel> GetChildren(int columnId)
        {
            return Dal.GetChildren(columnId);
        }
    }
}